package com.team9.fitness.mapper;

import com.team9.fitness.entity.UserProfile;
import org.apache.ibatis.annotations.*;

import java.util.Optional;

@Mapper
public interface UserProfileMapper {

        @Insert("INSERT INTO user_profile (user_id, name, height, weight, gender, birthday, des, location, avatar, created_at, updated_at) "
                        +
                        "VALUES (#{userId}, #{name}, #{height}, #{weight}, #{gender}, #{birthday}, #{des}, #{location}, #{avatar}, #{createdAt}, #{updatedAt})")
        @Options(useGeneratedKeys = true, keyProperty = "id")
        int insert(UserProfile userProfile);

        @Select("SELECT * FROM user_profile WHERE user_id = #{userId}")
        UserProfile selectByUserId(Long userId);

        @Update("UPDATE user_profile SET name = #{name}, height = #{height}, weight = #{weight}, gender = #{gender}, " +
                        "birthday = #{birthday}, des = #{des}, location = #{location}, avatar = #{avatar}, updated_at = #{updatedAt} WHERE user_id = #{userId}")
        int updateByUserId(UserProfile userProfile);

        @Delete("DELETE FROM user_profile WHERE user_id = #{userId}")
        int deleteByUserId(Long userId);

        @Select("SELECT * FROM user_profile WHERE id = #{id}")
        Optional<UserProfile> selectById(Long id);
}
